/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Signer;

import jWASA.Sample;
import jWASA.SignedSample;
import java.awt.RenderingHints.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author gianmariospacagna
 */
public class Signer {

    Key publicKey;
    Key privateKey;

    public Signer() {
    }

    public Signer(String algorithm) throws NoSuchAlgorithmException {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
        kpg.initialize(2048);
        KeyPair kp = kpg.genKeyPair();
        this.publicKey = (Key) kp.getPublic();
        this.privateKey = (Key) kp.getPrivate();
    }

    public Signer(Key publicKey, Key privateKey) {
        this.publicKey = publicKey;
        this.privateKey = privateKey;
    }

    /**
     * Sign the data using the private key
     * @param data Data to sign
     * @return signedData Signed Data
     */
    public SignedSample sign(Sample sample) {
        return new SignedSample(sample, sample.hashCode());
    }
}
